//
//  CZIncomeCell.m
//  TCProject
//
//  Created by admin on 16/2/1.
//  Copyright © 2016年 wise-wing. All rights reserved.
//

#import "CZIncomeCell.h"
#import "ZDWalletLog.h"
#import "CZIncomeDetailCell.h"

@interface CZIncomeCell()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *h1;
@property (weak, nonatomic) IBOutlet UILabel *v1;

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableViewHeightConstraint;

@end
@implementation CZIncomeCell

- (void)awakeFromNib {
    [self.tableView registerNib:[UINib nibWithNibName:@"CZIncomeDetailCell" bundle:nil] forCellReuseIdentifier:reuseIdentifier];
    self.tableView.clipsToBounds = YES;
    self.tableView.rowHeight = 96.f;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setLog:(ZDWalletLog *)log {
    _log = log;
    
    //    _h1.text = [NSString stringWithFormat:@"订单号: %@", _log.orderNum];
    _h1.text = _log.title;
    _v1.text = [NSString stringWithFormat:@"实际收入: +%.2f", _log.money];
    if (_log.type == 2) {
        //        _h1.text = log.title;
        _v1.text = [NSString stringWithFormat:@"-%.2f", _log.money];
    }
    
    [UIView animateWithDuration:kDefaultAnimDuration animations:^{
        if (_log.selected) {
            [self.tableView reloadData];
            _tableViewHeightConstraint.constant = _tableView.contentSize.height;
        } else {
            _tableViewHeightConstraint.constant = 0;
        }
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _log.serviceLogs.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CZIncomeDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    cell.log = _log.serviceLogs[indexPath.row];
    return cell;
}

@end

